package com.uchengwang.ui.cm_ui.cycle.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.cycle.bean.BottomBean;

import java.util.List;

/**
 * Created by U城网 on 2018/2/5.
 */

public class BottomAdapter extends BaseAdapter{
    private Context context;
    private List<BottomBean> list;

    public BottomAdapter(Context context, List<BottomBean> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BottomVH holder = null;
        if (convertView ==null){
            holder = new BottomVH();
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_bottom_tv, null);
            holder.bottom_ln = (LinearLayout) convertView.findViewById(R.id.bottom_ln);
            holder.bottom_tv = (TextView) convertView.findViewById(R.id.bottom_tv);
            holder.bottom_icon = (ImageView) convertView.findViewById(R.id.bottom_icon);

            convertView.setTag(holder);
        }else {
            holder = (BottomVH) convertView.getTag();
        }
        BottomBean bean = list.get(position);

        holder.bottom_tv.setTextColor(context.getResources().getColor(bean.getColor()));
        holder.bottom_tv.setText(bean.getName());
        if (bean.getResId() !=0){
            ImageManager.getInstance().loadImage(context, holder.bottom_icon, bean.getResId(), ImageManager.ImageType.NARMOL);
        }else {
            holder.bottom_icon.setVisibility(View.GONE);
        }

        if (bean.getBgId() != 0){
            holder.bottom_ln.setBackgroundResource(bean.getBgId());
        }else {
            holder.bottom_ln.setBackgroundResource(0);
        }
        return convertView;
    }

    private class BottomVH{
        private LinearLayout bottom_ln;
        private TextView bottom_tv;
        private ImageView bottom_icon;
    }
}
